/*
 * @(#)CitizenshipTransformer.java
 * Date 2013-08-17
 * Version 1.0
 * Author Jim Horner
 * Copyright (c)2012
 */


package us.hornerscorners.lamppost.pix.transformer;

import javax.enterprise.context.ApplicationScoped;

import javax.inject.Inject;

import org.hl7.v3.PRPAMT201301UV02Citizen;

import us.hornerscorners.lamppost.exception.ServiceActionException;

import us.hornerscorners.lamppost.hl7v3common.utils.HL7Utils;

import us.hornerscorners.lamppost.model.patient.Citizenship;

import us.hornerscorners.lamppost.transformer.AbstractTransformer;


/**
 *
 * @author jim
 */
@ApplicationScoped
public class CitizenshipTransformer
        extends AbstractTransformer<PRPAMT201301UV02Citizen, Citizenship> {

    /** Field description */
    @Inject
    private InstanceIdentifierTransformer instanceIdentifierTransformer;

    /** Field description */
    @Inject
    private PoliticalNationTransformer politicalNationTransformer;

    /**
     * Constructs ...
     *
     */
    public CitizenshipTransformer() {
        super();
    }

    /**
     * Method description
     *
     *
     * @param prpaCitizen
     *
     * @return
     */
    @Override
    public Citizenship transform(PRPAMT201301UV02Citizen prpaCitizen)
            throws ServiceActionException {

        Citizenship result = null;

        if (prpaCitizen != null) {

            result = new Citizenship();

            result.setEffectiveTime(
                HL7Utils.toEffectiveTime(prpaCitizen.getEffectiveTime()));

            result.getIdentifiers().addAll(
                this.instanceIdentifierTransformer.transform(prpaCitizen.getId()));

            result.setPoliticalNation(
                this.politicalNationTransformer.transform(
                    prpaCitizen.getPoliticalNation()));
        }

        return result;
    }
}
